js:

$(document).ready(function() {
  $(window).scroll(function() {
    if($(this).scrollTop() != 0) {
      $('#to-top').fadeIn();
    } else {
      $('#to-top').fadeOut();
    }
  });

  $('#to-top').click(function() {
    $('html, body').animate({scrollTop:0}, '300');
  });
});

css:

#to-top {
  position: fixed;
  bottom: 100px;
  right: 100px;
  display: none;
}

html:

<div id="to-top">Наверх</div>